#pragma once
#include "..\catalog\Catalog.h"
#include "ResultRow.h"

using namespace System;
using namespace System::Collections::Generic;

namespace squirrel
{
	namespace record
	{
		public ref class ResultTable
		{
		private:
			squirrel::catalog::TableInfo^ _TableInfo;
			List<ResultRow^>^ _ResultRows;

		public:
			ResultTable(squirrel::catalog::TableInfo^ tableInfo)
			{
				this->_TableInfo = tableInfo;
				this->_ResultRows = gcnew List<ResultRow^>();
			}

			property squirrel::catalog::TableInfo^ TableInfo
			{
				squirrel::catalog::TableInfo^ get()
				{
					return this->_TableInfo;
				}
			}

			property array<ResultRow^>^ Rows
			{
				array<ResultRow^>^ get() { return this->_ResultRows->ToArray(); }
			}

			int GetRowCount()
			{
				return this->_ResultRows->Count;
			}

			ResultRow^ GetRow(int index)
			{
				if(index < 0 || index >= this->_ResultRows->Count)
				{
					throw gcnew ArgumentOutOfRangeException("index");
				}
				return this->_ResultRows[index];
			}

			void DeleteRow(int index)
			{
				if(index < 0 || index >= this->_ResultRows->Count)
				{
					throw gcnew ArgumentOutOfRangeException("index");
				}
				this->_ResultRows->RemoveAt(index);
			}

			void AddRow(ResultRow^ row)
			{
				if(row == nullptr)
				{
					throw gcnew ArgumentNullException("row");
				}

				this->_ResultRows->Add(row);
			}

		};
	}
}